Skip to content

Fall back to open Positron notebooks in notebooks.getContext when none is the active editor pane#14842

Merged
nstrayer merged 5 commits into
mainfrom
fix/14762-assistant-find-notebooks
Jul 16, 2026
Merged

Fall back to open Positron notebooks in notebooks.getContext when none is the active editor pane#14842
nstrayer merged 5 commits into
mainfrom
fix/14762-assistant-find-notebooks

Conversation

@nstrayer

@nstrayer nstrayer commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #14762

There was a confusing state you could get into where when you navigate off of a positron notebook into a non-editor-type context like a data explorer etc we never triggered the event that caused the assistant chat to think it had left the notebook. This meant that the notebook was still "active" in the chat pane (e.g. the active runtime was the notebook) but when the assistant went to query the notebook the thing we gate on is the notebook being the active editor which if focus is on something like the data explorer then it is not. The result was a confused agent and user because the agent didnt have access to the notebook context it expected. This fixes that by letting the notebook tools search open but not focused editors for the correct notebook.

Agent generated notes 👇

positron.notebooks.getContext resolved the notebook only from the active editor pane, so assistant tools reported "no notebook is open in the editor" whenever focus was anywhere else (a Data Explorer or plot editor opened from the notebook, the chat editor, a split group, another tab) even though a Positron notebook was open. This PR adds a fallback: when no Positron notebook is the active pane, getContext resolves the open notebook attached to the foreground session (what the interpreter picker shows, and what assistant notebook mode is keyed on), then the most recently active open Positron notebook.

Two edge behaviors are deliberate:

  • When the active editor is a notebook in the built-in (Jupyter) editor, getContext still rejects with the actionable "reopen in the Positron Notebook Editor" error rather than falling back to a different open notebook.
  • When the foreground session's notebook editor has been closed, resolution falls back to the most recently active open notebook rather than targeting a closed one. (Assistant tool calls that pass an explicit notebook path verify it against the resolved notebook and error on mismatch, so a stale session can't silently redirect a path-addressed edit.)

Release Notes

New Features

  • N/A

Bug Fixes

Validation Steps

@:positron-notebooks @:assistant

Regression tests: src/vs/workbench/api/test/browser/positron/mainThreadNotebookFeatures.vitest.ts covers the fallback (open-but-inactive notebook, MRU order across multiple notebooks, foreground-session preference, closed foreground notebook, nothing open, and the built-in-editor error).

Manual check:

  1. Open a Positron Notebook (positron.notebook.enabled on) and run a cell so it has a session.
  2. Open a Data Explorer from the notebook (e.g. View a dataframe) so the notebook is no longer the active editor pane.
  3. Ask Posit Assistant something that reads the notebook (or invoke a notebook tool). It should find the notebook instead of replying "no notebook is open in the editor".
  4. With a second notebook also open, verify the assistant still targets the notebook attached to the current session, not the more recently touched one.
  5. Open a notebook in the built-in Jupyter editor as the active tab; notebook tools should still return the "reopen in the Positron Notebook Editor" guidance.

nstrayer added 5 commits July 13, 2026 09:26
positron.notebooks.getContext resolved the notebook only from the active
editor pane, so assistant tools reported 'no notebook is open in the
editor' whenever focus was in another editor (chat editor, split group,
another tab) even though a Positron notebook was open. Fall back to the
most recently active open Positron notebook, resolved through the editor
service's MRU list against registered notebook instances.
The confirmed repro for #14762 (Data Explorer or plot editor takes the
active pane while the notebook session stays foreground) shows assistant
notebook mode is keyed on the foreground session. Resolve that notebook
first so getContext agrees with the mode and the interpreter picker;
keep the MRU editor fallback for cases where the foreground session was
demoted (e.g. focus moved to a code file mid-turn).
@github-actions

Copy link
Copy Markdown

E2E Tests 🚀
This PR will run tests tagged with: @:critical @:positron-notebooks @:assistant

Why these tags?
Tag Source
@:critical Always runs (required)
@:positron-notebooks PR description
@:assistant PR description

More on automatic tags from changed files.

readme  valid tags

@nstrayer nstrayer requested a review from jmcphers July 13, 2026 17:19
@nstrayer nstrayer marked this pull request as ready for review July 15, 2026 15:44

@jmcphers jmcphers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG, was able to open a dataframe and still get Assistant context for the notebook.

Image

@nstrayer nstrayer merged commit 38ca282 into main Jul 16, 2026
27 checks passed
@nstrayer nstrayer deleted the fix/14762-assistant-find-notebooks branch July 16, 2026 01:14
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assistant has trouble finding Positron Notebooks even when they're open.

2 participants